
package com.insigma.business.qrcode.soldier.service.impl;


import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.common.util.AdminAreaCodeUtils;
import com.insigma.business.qrcode.soldier.dao.SoldierMessageInfoDao;
import com.insigma.business.qrcode.soldier.dto.SequenceNameConstant;
import com.insigma.business.qrcode.soldier.dto.SoldierMessageInfoBSearcher;
import com.insigma.business.qrcode.soldier.entity.DataStatsCDO;
import com.insigma.business.qrcode.soldier.entity.SoldierMessageInfoDO;
import com.insigma.business.qrcode.soldier.service.SoldierMessageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("soldierMessageInfoService")
public class SoldierMessageInfoServiceImpl implements SoldierMessageInfoService {

    @Autowired(required = false)
    private SoldierMessageInfoDao soldierMessageInfoDao;
    @Autowired(required = false)
    private SequenceGenerator sequenceGenerator;

    
    @Override
    public List<SoldierMessageInfoDO> search(final SoldierMessageInfoBSearcher soldierMessageInfoBSearcher) {
        return soldierMessageInfoDao.search(soldierMessageInfoBSearcher);
    }
   
    @Override
    public SoldierMessageInfoDO get(final String id){
        return soldierMessageInfoDao.get(id);
    }

    
    @Override
    public Integer insert(final SoldierMessageInfoDO soldierMessageInfoDO){
        soldierMessageInfoDO.setId(sequenceGenerator.genKey(SequenceNameConstant.SOLDIER_MESSAGE_INFO_ID));
        return soldierMessageInfoDao.insert(soldierMessageInfoDO);
    }

    
    @Override
    public Integer update(final SoldierMessageInfoDO soldierMessageInfoDO){
        return soldierMessageInfoDao.update(soldierMessageInfoDO);
    }

    
    @Override
    public Integer delete(final String id, final String modifierType, final String modifierId){
        return soldierMessageInfoDao.delete(id,modifierType,modifierId);
    }

    @Override
    public List<SoldierMessageInfoDO> listRemindAndUnreadMessageInfo(String soldierId) {
        return soldierMessageInfoDao.listRemindAndUnreadMessageInfo(soldierId);
    }

    @Override
    public List<SoldierMessageInfoDO> listRemindAndUnreadMessageInfoByIdCardNo(String idCardNo) {
        return soldierMessageInfoDao.listRemindAndUnreadMessageInfoByIdCardNo(idCardNo);
    }

    @Override
    public List<SoldierMessageInfoDO> listAllCrowdAndValid() {
        return soldierMessageInfoDao.listAllCrowdAndValid();
    }

    @Override
    public List<SoldierMessageInfoDO> searchMyMessage(SoldierMessageInfoBSearcher soldierMessageInfoBSearcher) {
        return soldierMessageInfoDao.searchMyMessage(soldierMessageInfoBSearcher);
    }
    @Override
    public List<SoldierMessageInfoDO> searchBusPushed(String idCard, String idCardNo) {
        return soldierMessageInfoDao.searchBusPushed(idCard, idCardNo);
    }

    @Override
    public int countUnreadOfIdCardNo(String cachedIdCardNo) {
        return soldierMessageInfoDao.countUnreadOfIdCardNo(cachedIdCardNo);
    }

    @Override
    public List<SoldierMessageInfoDO> searchMessageOfCrowd(SoldierMessageInfoBSearcher soldierMessageInfoBSearcher) {
        return soldierMessageInfoDao.searchMessageOfCrowd(soldierMessageInfoBSearcher);
    }

    @Override
    public int countByType(String type, String month) {
        return soldierMessageInfoDao.countByType(type, month);
    }

    @Override
    public List<SoldierMessageInfoDO> listByBizType(String bizType) {
        return soldierMessageInfoDao.listByBizType(bizType);
    }

    @Override
    public Integer countByTypeByAreaCode(String bizType, String adminAreaCode) {
        adminAreaCode = AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode);
        return soldierMessageInfoDao.countByTypeByAreaCode(bizType, adminAreaCode);
    }

    @Override
    public List<DataStatsCDO> groupByArea(String bizType, String adminAreaCode) {
        int level = AdminAreaCodeUtils.getLevel(adminAreaCode);
        String areaLike = AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode) + "%";
        int nextLevel = level + 1;
        int levelLength = AdminAreaCodeUtils.getLevelLength(nextLevel);
        return soldierMessageInfoDao.groupByArea(areaLike, nextLevel, levelLength, bizType);
    }

}
